package com.lazyfish.jdbc;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import java.util.List;

public class JdbcTemplateTest {
    public static void main(String[] args) {
        ApplicationContext applicationContext  =  new ClassPathXmlApplicationContext("applicationContext.xml");
        AccountDao accountDao = (AccountDao)applicationContext.getBean("accountDao");
        Account account = new Account();
        account.setUsername("wdnmd");
        account.setBalance(500.00);
        int num = accountDao.addAccount(account);
        System.out.println(num);
//        JdbcTemplate jdbcTemplate = (JdbcTemplate) applicationContext.getBean("jdbcTemplate");
//        String sql = "select * from account";
//        RowMapper<Account> rowMapper = new BeanPropertyRowMapper<Account>(Account.class);
//        List<Account> accounts = jdbcTemplate.query(sql,rowMapper);
//        for (Account act : accounts){
//            System.out.println(act.getUsername());
//        }

    }
}
